package com.msmall.community.team.action.html;

import java.io.File;
import java.util.List;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantAjax;
import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.bbs.model.Thread;
import com.msmall.community.bbs.model.Topic;
import com.msmall.community.bbs.model.Thread;
import com.msmall.community.bbs.service.TopicManager;
import com.msmall.community.team.model.Team;
import com.msmall.community.team.model.TeamProperty;
import com.msmall.community.team.model.TeamTopic;
import com.msmall.community.team.model.TeamUser;
import com.msmall.community.team.service.TeamManager;

public class TeamAction extends HTMLBaseAction{

	private static final long serialVersionUID = -6245126770897508457L;
	protected static final String SESSION_TEAM_KEY = "SESSION_TEAM_KEY";
	protected static final String SESSION_TEAM_TOPIC_KEY = "SESSION_TEAM_TOPIC_KEY";
	protected static final String SESSION_TEAM_TOPIC_TEAMID_KEY = "SESSION_TEAM_TOPIC_TEAMID_KEY";
	protected static final String SESSION_TEAM_TOPIC_TITLE_KEY = "SESSION_TEAM_TOPIC_TITLE_KEY";
	protected static final String SESSION_TEAM_TOPIC_CONTENT_KEY = "SESSION_TEAM_TOPIC_CONTENT_KEY";
	protected static final String SESSION_TEAM_TOPIC_ORIGINAL_KEY = "SESSION_TEAM_ORIGINAL_KEY";
	protected static final String SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY = "SESSION_TEAM_SHAREPUBLIC_KEY";
	protected static final String SESSION_TEAM_TOPIC_SHARETEAM_KEY = "SESSION_TEAM_TOPIC_SHARETEAM_KEY";
	
	private Long ttid;//TeamTopicid
	
	private Long teamid;
	
	private Long tuid; //teamuser id
	
	private String applyPaper;
	
	private Short original; //创建帖TeamTopic的来源  转载 1， 原创2 Constantdb.TOPIC_ORIGINAL_
	
	private String sharePublic; //是否共享到社区 1共享；2不共享
	
	private String title;//创建TeamTopic的标题
	
	private String content;//创建TeamTopic的内容
	
	private Long sharedBoardId;//创建TeamTopic 发表到社区时，共享的社区ID
	
	private String shareTeam; //创建TeamTopic 是否分享给联盟组， 1分享
	
	private String invite;//邀请用户的被邀请人，目前只按昵称邀请
	private Long messageid;//接受/拒绝群组邀请时的消息ID
	
	private TeamTopic tTopic;
	private Topic topic;
	private Thread thread;
	
	private Team team;
	
	private TeamUser teamUser;
	
	private TeamUser creator;//组创建者
	
	private TeamProperty property;
	
	private List<TeamUser> managers;//获得组的管理者，不包括创建者 
	
	// 获得组的普通成员，不包括创建者和管理者 
	private List<TeamUser> users;
	
	private List<TeamUser> members;
	
	private File logo;
	private String logoContentType;
	private String logoFileName;
	
	private TeamManager teamManager;
	
	private TopicManager topicManager;
	
	/**
	 * 用户进入组首页；显示 组成员信息,组话题
	 */
	public String execute(){
		try{
		if(teamid != null && teamid.longValue() != 0l){
			team = (Team) teamManager.get(Team.class, teamid);
			if(team != null && team.getStatus().compareTo(Team.STATUS_NORMAL) == 0){
				teamUser = teamManager.getTeamUser(getUserid(), teamid);
				TeamProperty teamProperty = teamManager.getTeamVisit(teamid);
				if(teamProperty != null){
					if(TeamProperty.VALUE_DEFAULT_ONLY_MEMBER.equals(teamProperty.getPropertyValue())){
						if(teamUser != null){
							if(!(TeamUser.STATUS_NORMAL.intValue() == teamUser.getStatus().intValue())){
								return "ban";//非正常状态不能访问
							}
						}else{
							return "ban";//非组员不能访问
						}
					}
				}
				//teamProperty == null 默认设置，所有人都能访问
				page.setPageSize(40);
				teamManager.getPaginationByTeam(page, teamid);//组话题
				creator = teamManager.getTeamCreator(teamid);
				managers = teamManager.getTeamManagers(teamid,false);
				users = teamManager.getTeamMembers(teamid);
				
				if(teamUser != null && TeamUser.STATUS_NORMAL.intValue() == teamUser.getStatus().intValue()){
					return "member";
				}
				return "vister";
			}
		}
		}catch(Exception e){
			log.error(e);
		}
		return "TEAM_LIST";
	}
	
	/**
	 * 显示所有的组列表
	 */
	public String list(){
		page.setPageSize(10);
		teamManager.getAvaliableTeam(page);
		page.setUrl(ConstantUrl.HTML_TEAM_LIST);
		return SUCCESS;
	}
	/**
	 * 进入创建组页面 
	 */
	public String createTeam(){
		if(!teamManager.canCreateTeam(getUserid())){
			return ERROR;
		}
		teamid = null;
		if(team == null){
			team = (Team) getFromSession(SESSION_TEAM_KEY);
		}
		return SUCCESS;
	}
	/**
	 * 创建/更新组信息
	 */
	public String saveTeam(){
		if(!teamManager.canCreateTeam(getUserid())){
			message = getText("html.team.create.amount.overflow");
			setToSession(SESSION_TEAM_KEY, team);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(!getIsLogin()){
			message = getText("common.authentication.anonymous");
			setToSession(SESSION_TEAM_KEY, team);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		int result  = teamManager.validateTeam(team);
		if(result == 1){
			message = getText("html.team.create.name.existed");
		}
		if(result == 2){
			message = getText("html.team.create.name.illegal");
		}
		if(result == 3){
			message = getText("html.team.create.name.length.short");
		}
		if(result == 4){
			message = getText("html.team.create.name.length.long");
		}
		if(result == 5){
			message = getText("html.team.create.description.illegal");
		}
		if(result == 6){
			message = getText("html.team.create.description.length.short");
		}
		if(result == 7){
			message = getText("html.team.create.description.length.long");
		}
		if(result != 0){
			setToSession(SESSION_TEAM_KEY, team);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		boolean ok = teamManager.createTeam(getUserid(), team.getName(), team.getDescription());
		if(!ok){
			message = getText("html.team.create.error.unknown");
			setToSession(SESSION_TEAM_KEY, team);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		team = teamManager.loadTeamByName(team.getName());
		removeFromSession(SESSION_TEAM_KEY);
		removeFromSession(SESSION_MESSAGE_KEY);
		return SUCCESS;
	}
	/**
	 * 进入填写申请加入组申请信息页面
	 */
	public String apply(){
		if (!getIsLogin()) {
			return "unlogin";
		}
		team = (Team) teamManager.get(Team.class, teamid);
		if(teamManager.getTeamUser(getUserid(), getTeamid()) != null || team.getStatus().compareTo(Team.STATUS_NORMAL) != 0){
			return ERROR;
		}
		return SUCCESS;
	}
	/**
	 * 用户申请加入组 
	 */
	public String join(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			if(teamManager.getTeamUser(getUserid(), getTeamid()) != null){
				buffer.append(createResult("false"));
				buffer.append(createEasyContent(getText("html.team.apply.error.again")));
			}else{
				teamManager.join(getUserid(), teamid, applyPaper);
				buffer.append(createResult("true"));
			}
		}catch(Exception e){
			buffer.append(createResult("false"));
			buffer.append(createEasyContent(getText("html.team.apply.error")));
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	/**
	 * 退组
	 */
	public String leave(){
		teamManager.leave(getUserid(), teamid);
		return SUCCESS;
	}
	/**
	 * 组长进入更新组信息页面
	 */
	public String updateTeam(){
		try{
			teamUser = teamManager.getTeamCreator(teamid);
			if(teamUser.getPosition().compareTo(TeamUser.POSITION_CHAIRMAN) == 0){
				team = (Team) teamManager.get(Team.class, teamid);
				return SUCCESS;
			}else{
				return ERROR;
			}
		}catch(Exception e){
			return ERROR;
		}
	}
	/**
	 * 保存组长修改过的组信息; 组名/组描述
	 */
	public String saveUpdateTeam(){
		if(!getIsLogin()){
			message = getText("common.authentication.anonymous");
			setToSession(SESSION_TEAM_KEY, team);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		int result  = teamManager.validateTeam(team);
		if(result == 2){
			message = getText("html.team.create.name.illegal");
		}
		if(result == 3){
			message = getText("html.team.create.name.length.short");
		}
		if(result == 4){
			message = getText("html.team.create.name.length.long");
		}
		if(result == 5){
			message = getText("html.team.create.description.illegal");
		}
		if(result == 6){
			message = getText("html.team.create.description.length.short");
		}
		if(result == 7){
			message = getText("html.team.create.description.length.long");
		}
		if(result != 0 && result != 1){
			setToSession(SESSION_TEAM_KEY, team);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		result = teamManager.updateTeam(getUserid(), teamid, team.getName(), team.getDescription());
		if(result == 0){
			removeFromSession(SESSION_TEAM_KEY);
			removeFromSession(SESSION_MESSAGE_KEY);
			return SUCCESS;
		}else if(result == 1){
			message = getText("html.team.update.notcreator");
		}else if(result == 9){
			message = getText("html.team.update.error");
		}
		setToSession(SESSION_TEAM_KEY, team);
		setToSession(SESSION_MESSAGE_KEY, message);
		return INPUT;
	}
	
	/**
	 * 组长/副组长进入管理组员信息页面,显示所有组员列表
	 */
	public String manageUser(){
		try{
			teamUser = teamManager.getTeamUser(getUserid(), teamid);
			if(teamUser.getPosition().intValue() == TeamUser.POSITION_CHAIRMAN || (teamUser.getPosition().intValue() == TeamUser.POSITION_VICE_CHAIRMAN && teamUser.getStatus().intValue() == TeamUser.STATUS_NORMAL)){
				team = (Team) teamManager.get(Team.class, teamid);
				members = teamManager.getMembers(teamid, -1);
				return SUCCESS;
			}else{
				return ERROR;
			}
		}catch(Exception e){
			return ERROR;
		}
	}
	/**
	 * 组长/副组长管理组员信息页面，单个用户信息
	 */
	public String manageUserUpdate(){
		try{
			teamUser = (TeamUser) teamManager.get(TeamUser.class, tuid);
			creator = teamManager.getTeamUser(getUserid(), teamUser.getTeamid());//当前登录系统的用户
			if(creator.getPosition().compareTo(TeamUser.POSITION_CHAIRMAN) == 0){//管理者是组长
				return SUCCESS;
			}else if((creator.getPosition().compareTo(TeamUser.POSITION_VICE_CHAIRMAN) == 0 && creator.getStatus().compareTo(TeamUser.STATUS_NORMAL) == 0)){
				//管理者是有效的副组长
				if(teamUser.getPosition().compareTo(TeamUser.POSITION_CHAIRMAN)==0 
						|| (teamUser.getPosition().compareTo(TeamUser.POSITION_VICE_CHAIRMAN) == 0 && teamUser.getUserid().compareTo(creator.getUserid()) != 0)){
					//副组长不能管理 组长/其他副组长
					return ERROR;
				}
				return SUCCESS;
			}
			return ERROR;
		}catch(Exception e){
			return ERROR;
		}
	}
	/**
	 * 组长/副组长保存修改后的单个用户信息
	 */
	public String manageUserSave(){
		try{
			teamid = teamUser.getTeamid();
			teamManager.saveTeamUser(getUserid(), teamUser);
			return SUCCESS;
		}catch(Exception e){
			return ERROR;
		}
	}
	/**
	 * 组长/副组长进入邀请组员加入页面
	 */
	public String inviteUser(){
		try{
			teamUser = teamManager.getTeamUser(getUserid(), teamid);
			if(teamUser.getPosition().compareTo(TeamUser.POSITION_CHAIRMAN) ==0 
					|| (teamUser.getPosition().compareTo(TeamUser.POSITION_VICE_CHAIRMAN)==0 && teamUser.getStatus().compareTo(TeamUser.STATUS_NORMAL)==0)){
				return SUCCESS;
			}else{
				return ERROR;
			}
		}catch(Exception e){
			return ERROR;
		}
	}
	// 邀请用户
	public String doInviteUser(){
		teamManager.inviteUser(getUserid(), teamid, invite);
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE)
		.append(createResult("true"))
		.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	// 用户接受邀请加入组
	public String agreeInvite(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			teamManager.inviteAgress(getUserid(), teamid, messageid);
			buffer.append(createResult("true"));
		}catch(Exception e){
			buffer.append(createResult("false"));
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	// 用户接受邀请加入组
	public String rejectInvite(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			teamManager.inviteReject(getUserid(), teamid, messageid);
			buffer.append(createResult("true"));
		}catch(Exception e){
			buffer.append(createResult("false"));
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	/**
	 * 组长/副组长删除组话题
	 */
	public String deleteTopic(){
		TeamTopic tTopic = (TeamTopic) teamManager.get(TeamTopic.class, ttid);
		teamManager.deleteTeamTopic(getUserid(), ttid);
		teamid = tTopic.getTeamid();
		return SUCCESS;
	}
	
	/**
	 * 进入创建帖子页面
	 * @return
	 */
	public String createTTopic(){
		if(teamid == null){
			return "TEAM_LIST";
		}
		team = (Team) teamManager.get(Team.class, teamid);
		if(title == null || content == null){
			title = (String) getFromSession(SESSION_TEAM_TOPIC_TITLE_KEY);
			content = (String) getFromSession(SESSION_TEAM_TOPIC_CONTENT_KEY);
			original = (Short) getFromSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY);
			getFromSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY);
			getFromSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY);
			getFromSession(SESSION_TEAM_TOPIC_TEAMID_KEY);
		}
		sharePublic = ConstantDB.TEAM_TOPIC_SHARE_PUBLIC;
		shareTeam = ConstantDB.TEAM_TOPIC_SHARE_TEAM;
		if(message == null){
			message = (String) getFromSession(SESSION_MESSAGE_KEY);
			if(message!= null && getText("common.authentication.anonymous").equalsIgnoreCase(message)){
				if(getIsLogin()){
					message = null;
					removeFromSession(SESSION_MESSAGE_KEY);
				}
			}
		}
		return SUCCESS;
	}
	/**
	 * 保存帖子，用于创建和修改
	 * @return
	 */
	public String saveTTopic(){
		if(!getIsLogin()){
			message = getText("common.authentication.anonymous");
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}

		int validtitle = topicManager.validateTopicTitle(title);
		if(validtitle == 2){
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			message = getText("html.bbs.topic.create.title.length.short");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(validtitle == 3){
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			message = getText("html.bbs.topic.create.title.length.long");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(validtitle == 4){
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			message = getText("html.bbs.topic.create.title.illegal");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		int validcontent = topicManager.validateTopicContent(content);
		if(validcontent == 2){
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			message = getText("html.bbs.topic.create.content.length.short");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(validcontent == 3){
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			message = getText("html.bbs.topic.create.content.length.long");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(validcontent == 4){
			setToSession(SESSION_TEAM_TOPIC_TEAMID_KEY, teamid);
			setToSession(SESSION_TEAM_TOPIC_TITLE_KEY, title);
			setToSession(SESSION_TEAM_TOPIC_CONTENT_KEY, content);
			setToSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY, original);
			setToSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY, sharePublic);
			setToSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY, shareTeam);
			message = getText("html.bbs.topic.create.content.illegal");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		teamManager.newTeamTopic(getUserid(), teamid,original, title, content, getUserAgentType(), sharePublic, sharedBoardId, ConstantDB.TEAM_TOPIC_SHARE_TEAM.equals(shareTeam)?true:false);
		removeFromSession(SESSION_TEAM_TOPIC_TEAMID_KEY); //清空
		removeFromSession(SESSION_TEAM_TOPIC_TITLE_KEY); //清空
		removeFromSession(SESSION_TEAM_TOPIC_CONTENT_KEY); //清空
		removeFromSession(SESSION_TEAM_TOPIC_ORIGINAL_KEY);
		removeFromSession(SESSION_TEAM_TOPIC_SHAREPUBLIC_KEY);
		removeFromSession(SESSION_TEAM_TOPIC_SHARETEAM_KEY);
		removeFromSession(SESSION_MESSAGE_KEY); //清空
		return SUCCESS;
	}
	/**
	 * 查看群组帖子，未实现
	 */
	public String viewTTopic(){
//		try{
//			tTopic = (TeamTopic) teamManager.get(TeamTopic.class, ttid);
//			topic = (Topic)topicManager.get(Topic.class, tTopic.getTopicid());
//		}catch(Exception e){
//			return "boardIndex";
//		}
//		if(message == null){ // 当发表回复时，出错挑战到此，需要从SESSION中取得出错信息
//			message = (String) getFromSession(SESSION_MESSAGE_KEY);
//			if(message!= null && getText("common.authentication.anonymous").equalsIgnoreCase(message)){
//				if(getIsLogin()){
//					message = null;
//					removeFromSession(SESSION_MESSAGE_KEY);
//				}
//			}
//		}
//		if(thread == null){ // 当发表回复时，出错挑战到此，需要从SESSION中取得出错信息
//			thread = (Thread) getFromSession(SESSION_THREAD_KEY);
//		}
//		if(topic.getEnabled().compareTo((short)0) == 0){
//			bid = topic.getBoard().getBoardId();
//			return "boardIndex";
//		}
//		topicManager.addClickAmount(topic);
//		board = topic.getBoard();
//		bid= board.getBoardId();
//		
//		page.setPageSize(30);
//		topicManager.getThreadPaginationByTopic(page, getUserid(), tid, null);
//		page.setUrl(ConstantUrl.HTML_TOPIC_VIEW + "?bid="+ bid+"&tid="+tid);
		return SUCCESS;
	}
	//进入上传LOGO页面
	public String uploadLogo(){
		creator = teamManager.getTeamCreator(teamid);
		if(creator.getUserid().compareTo(getUserid()) != 0){
			return ERROR;
		}
		return SUCCESS;
	}
	/**
	 * 保存LOGO
	 */
	public String saveLogo(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			team = teamManager.saveTeamLogo(logo, logoFileName, getUserAgentType(), getUserid(), teamid);
			if(team != null){
				buffer.append(createResult("true"))
				.append(ConstantAjax.CONTENT_PRE)
				.append(team.getLogo())
				.append(ConstantAjax.CONTENT_SUFF);
			}else{
				buffer.append(createResult("false"));
			}
		}catch(Exception e){
			buffer.append(createResult("false"));
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	//进入修改TEAM访问权限页面
	public String teamVisit(){
		creator = teamManager.getTeamCreator(teamid);
		if(creator.getUserid().compareTo(getUserid()) != 0){
			return ERROR;
		}
		property = teamManager.getTeamVisit(teamid);
		return SUCCESS;
	}
	/**
	 * 保存TEAM访问权限
	 */
	public String saveTeamVisit(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			int result = teamManager.setTeamVisit(getUserid(), teamid, property.getPropertyValue());
			if(result == 0){
				buffer.append(createResult("true"));
			}else{
				buffer.append(createResult("false"));
			}
		}catch(Exception e){
			buffer.append(createResult("false"));
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	// 进入 组用户修改自己在组中的昵称 的页面
	public String updateMemberNickname(){
		teamUser = teamManager.getTeamUser(getUserid(), teamid);
		return SUCCESS;
	}
	// 组用户修改自己在组中的昵称
	public String saveMemberNickname(){
		teamid = teamUser.getTeamid();
		teamUser = teamManager.saveTeamUserNickname(getUserid(), teamid, teamUser.getNickname());
		return SUCCESS;
	}
	
	public void setTeamManager(TeamManager teamManager) {
		this.teamManager = teamManager;
	}
	public Long getTeamid() {
		return teamid;
	}
	public void setTeamid(Long teamid) {
		this.teamid = teamid;
	}
	public Team getTeam() {
		return team;
	}
	public void setTeam(Team team) {
		this.team = team;
	}
	public String getApplyPaper() {
		return applyPaper;
	}
	public void setApplyPaper(String applyPaper) {
		this.applyPaper = applyPaper;
	}
	public List<TeamUser> getMembers() {
		return members;
	}
	public void setMembers(List<TeamUser> members) {
		this.members = members;
	}

	public TeamUser getTeamUser() {
		return teamUser;
	}

	public void setTeamUser(TeamUser teamUser) {
		this.teamUser = teamUser;
	}

	public TeamUser getCreator() {
		return creator;
	}

	public void setCreator(TeamUser creator) {
		this.creator = creator;
	}

	public List<TeamUser> getManagers() {
		return managers;
	}

	public void setManagers(List<TeamUser> managers) {
		this.managers = managers;
	}

	public List<TeamUser> getUsers() {
		return users;
	}

	public void setUsers(List<TeamUser> users) {
		this.users = users;
	}

	public Long getTtid() {
		return ttid;
	}

	public void setTtid(Long ttid) {
		this.ttid = ttid;
	}

	public Long getTuid() {
		return tuid;
	}

	public void setTuid(Long tuid) {
		this.tuid = tuid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Short getOriginal() {
		return original;
	}

	public void setOriginal(Short original) {
		this.original = original;
	}

	public String getSharePublic() {
		return sharePublic;
	}

	public void setSharePublic(String sharePublic) {
		this.sharePublic = sharePublic;
	}

	public Long getSharedBoardId() {
		return sharedBoardId;
	}

	public void setSharedBoardId(Long sharedBoardId) {
		this.sharedBoardId = sharedBoardId;
	}

	public String getShareTeam() {
		return shareTeam;
	}

	public void setShareTeam(String shareTeam) {
		this.shareTeam = shareTeam;
	}

	public TeamTopic getTTopic() {
		return tTopic;
	}

	public void setTTopic(TeamTopic topic) {
		tTopic = topic;
	}

	public File getLogo() {
		return logo;
	}

	public void setLogo(File logo) {
		this.logo = logo;
	}

	public String getLogoContentType() {
		return logoContentType;
	}

	public void setLogoContentType(String logoContentType) {
		this.logoContentType = logoContentType;
	}

	public String getLogoFileName() {
		return logoFileName;
	}

	public void setLogoFileName(String logoFileName) {
		this.logoFileName = logoFileName;
	}

	public String getInvite() {
		return invite;
	}

	public void setInvite(String invite) {
		this.invite = invite;
	}

	public Long getMessageid() {
		return messageid;
	}

	public void setMessageid(Long messageid) {
		this.messageid = messageid;
	}

	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	public Thread getThread() {
		return thread;
	}

	public void setThread(Thread thread) {
		this.thread = thread;
	}

	public TeamProperty getProperty() {
		return property;
	}

	public void setProperty(TeamProperty property) {
		this.property = property;
	}

	public void setTopicManager(TopicManager topicManager) {
		this.topicManager = topicManager;
	}
}
